﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BuildDemoUser(10);
        }
    }

    protected void btnUploading_Click(object sender, EventArgs e)
    {
        //if (FileUpload1.HasFile)
        //{            
            
        //    //StreamingServiceClient ssClient = new StreamingServiceClient();
        //    //RemoteFileInfo uploadRequestInfo = new RemoteFileInfo();
        //    ////FileStream stream = FileUpload1.PostedFile.InputStream;
        //    //uploadRequestInfo.FileName = FileUpload1.FileName;
        //    //uploadRequestInfo.Length = FileUpload1.PostedFile.ContentLength;            
        //    //uploadRequestInfo.FileByteStream = FileUpload1.PostedFile.InputStream;
        //    //uploadRequestInfo.FolderId = 0;
        //    //uploadRequestInfo.Owner = "";
        //    ////ssClient.UploadFile(uploadRequestInfo);
        //    ////ssClient.UploadFile(uploadRequestInfo.FileName, 0, uploadRequestInfo.Length, "", uploadRequestInfo.FileByteStream);
        //    //ssClient.UploadFile(uploadRequestInfo);            
            
        //}
    }

    private void BuildDemoUser(int amount)
    {
        //this.ddlUsers.Items.Add(new ListItem("<User>","-1"));
        //for (int i = 0; i < amount; i++)
        //{
        //    this.ddlUsers.Items.Add(new ListItem("user" + (i + 1).ToString(), (i + 1).ToString()));
        //}
    }

    private void BuildFolder()
    {
        //int UserId = Convert.ToInt32(this.ddlUsers.SelectedValue);
        //if (UserId > 0)
        //{
        //    StreamingServiceClient proxy=new StreamingServiceClient();
        //    string username = this.ddlUsers.SelectedItem.Text;
        //    GetFoldersRequest request = new GetFoldersRequest();
        //    request.parentId = -1;
        //    request.owner = username;
        //    request.sortBy = 0;
        //    request.isSortAscending = true;
        //    request.pageSize = 100;
        //    request.pageIndex = 1;
        //    GetFoldersResponse respone = proxy.GetFolders(request);
        //    proxy.Close();
        //    Folder first = new Folder();
        //    first.Id = -1;
        //    first.FolderName = "< Folder >";
        //    respone.GetFoldersResult.Insert(0,first);
        //    this.ddlFolder.DataSource = respone.GetFoldersResult;
        //    this.ddlFolder.DataTextField = "FolderName";
        //    this.ddlFolder.DataValueField = "Id";
        //    this.ddlFolder.DataBind();            
        //}
    }

    protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.BuildFolder();
    }

    protected void lbtnNewFolder_Click(object sender, EventArgs e)
    {
        Response.Redirect(@"~/Folders/AddFolder.aspx");
    }

    protected void ddlFolder_SelectedIndexChanged(object sender, EventArgs e)
    {
        BuildFiles();
    }

    private void BuildFiles()
    {
        //int folderId = Convert.ToInt32(this.ddlFolder.SelectedValue);
        //StreamingServiceClient proxy = new StreamingServiceClient();
        //GetFilesRequest request = new GetFilesRequest(folderId, 0, true, 100, 1);
        //GetFilesResponse respone = proxy.GetFiles(request);
        //proxy.Close();
        //this.gvFiles.DataSource = respone.GetFilesResult;
        //this.gvFiles.DataBind();
    }
    protected void lbtnNewFile_Click(object sender, EventArgs e)
    {
        Response.Redirect(@"~/Files/AddFile.aspx");
    }
}
